//
//  MMS.hpp
//  MMS
//
//  Created by 王翛然 on 16/8/9.
//  Copyright © 2016年 王翛然. All rights reserved.
//

#ifndef MMS_hpp
#define MMS_hpp

#include <stdio.h>
#include "DatabaseOperate.hpp"
#include "Member.hpp"

class MMS
{
public:
    MMS(): con(), result(nullptr)
    { }
    
    void addMember(Member &mem);
    void addCardToMember(const std::string &memberName);

    void addCardToMember(const std::string &memberName, int times);
    std::string itoa(int num);
    std::string getMemberId(int num);
    
private:
    int executeSql(const std::string &sql)
    {
        int tag = con.executeSql(sql.data());
        if (!tag)
            result = con.fetchResult();
        return tag;
    }

    void updateMember(const Member &mem);
    bool checkResult();
    bool check(const std::string &sql);
    bool checkMember(const std::string &memberName);
    bool checkCard(const std::string &memberName);
    void mysqlFreeResult();
private:
    DatabaseOp con;
    MYSQL_RES *result;
};
#endif /* MMS_hpp */
